<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>add</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="__STATIC__/xadmin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/xadmin/css/xadmin.css">
    <script type="text/javascript" src="__STATIC__/xadmin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/xadmin/js/xadmin.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" onsubmit="javascript:return false;"> 
                <label class="  x-red" style="padding: 5px 10px;    padding: 0px 30px; font-size: 16px;  display: block; line-height: 2; margin: 0; box-sizing: border-box;">第一步：</label>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>下载模板：</label>
                    <div class="layui-input-inline" style="padding: 9px 15px;">
                        <a href="/static/demo.xls">报表数据导入模板.xls</a>
                    </div>
                </div>
                <hr>
                <label class="  x-red" style="padding: 5px 10px;    padding: 0px 30px; font-size: 16px;  display: block; line-height: 2; margin: 0; box-sizing: border-box;">第二步：</label>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>上传文件：</label>
                    <div class="layui-input-inline">
                        <input type="file" name="files" id="excel" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn" lay-filter="add" lay-submit="">确认</button>
                </div>
            </form>
        </div>
    </div>

<script>

    layui.use(['laydate', 'form'],function() {
        var laydate = layui.laydate;
        $=layui.jquery;
        var form = layui.form;
        var layer=layui.layer;
        //执行一个laydate实例
        laydate.render({
            elem: '#optime' //指定元素
        });
        form.on('submit(add)', function(data) {
            var excel = $('#excel').val();
            if(excel == ''){
                layer.msg('请上传文件!',{icon:2,time:3000});
                return false;
            }
            var formData = new FormData();
            formData.append("files", document.getElementById("excel").files[0]);
            formData.append('account',data.field.account);
            formData.append('a_id',data.field.a_id);
            formData.append('ader_id',data.field.ader_id);
            console.log(formData);
            $.ajax({
                type: "POST",//方法类型
                url: "{:url('addExcel')}",//url
                data: formData,
                contentType: false,//这里
                processData: false,//这两个一定设置为false
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result.code == 1) {
                        /*layer.closeAll();
                        layer.msg('共导入：' + result.data.all + "条数据<br/>成功：" + result.data.end + "条", {
                            time: 10000, //20s后自动关闭
                            btn: ['知道了'],
                            yes: function () {
                                    // window.location.reload();
                            }
                        });*/
                    }
                },
                error: function () {
                    layer.msg('异常!',{icon:2,time:3000});
                }
            });
        })
    });
</script>

</body>
</html>